Component({
  properties: {
    css: {
      type: String
    }
  },
  attched() {
    
  },
  methods: {
    touchstart( e ) {
      console.log('touch start');
      this.startX = this.moveX = e.changedTouches[0].clientX
      this.startY = this.moveY = e.changedTouches[0].clientY
    },
    touchmove(e) {
      let 
        startX = this.startX,
        startY = this.startY;
      this.moveX = e.changedTouches[0].clientX;
      this.moveY = e.changedTouches[0].clientY;
      let 
        moveX = this.moveX,
        moveY = this.moveY;
      this.angle = this.moveAngle({startX, startY}, {moveX, moveY});
    },
    touchend(e) {
      var 
        startX = this.startX,
        moveX  = this.moveX,
        angle  = this.angle;
      this.triggerEvent('touchnormal');
      if ( angle > 30 ) return;
      if ( moveX - startX > 20 ) {
        this.triggerEvent('touchright');
        console.log( '右滑' );
      } 
      if (startX - moveX > 20) {
        this.triggerEvent('touchleft');
        console.log( '左滑' );
      }
    },
    /**
     * 计算滑动角度
     * @param {Object} start 起点坐标
     * @param {Object} end 终点坐标
     */
    moveAngle: function (startPoint, endPOint) {
      var 
        _X = endPOint.X - startPoint.X,
        _Y = endPOint.Y - startPoint.Y;
      return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
    }
  }
})